package net.stsmedia.financemanager.service.impl;

import net.stsmedia.financemanager.dao.GenericDAOWithJPA;
import net.stsmedia.financemanager.domain.Person;
import net.stsmedia.financemanager.service.PersonService;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * This is a service layer implementation for {@link PersonService}. Note that
 * most of these methods from the interface are implemented by
 * {@link GenericDAOWithJPA}.
 * <p/>
 * The findByLastName method has been added to demonstrate how a custom method
 * is implemented in {@link PersonServiceImpl}.
 * <p/>
 * This class also provides the functionality of the repository. More
 * information about this in my blog article entitled 'Spring Finance > Part 3:
 * DDD, JPA & Transactions' published at StSMedia.net
 *
 * @author Stefan Schmidt
 * @since 0.1
 */
@Service("personService")
@Repository
public class PersonServiceImpl extends GenericDAOWithJPA<Person, Long> implements PersonService {

    // custom repository method

    public List<Person> findByLastName(String lastName) {
        return super.entityManager.createQuery("Select p from Person p where p.lastName = :lastName").setParameter("lastName", lastName).getResultList();
    }
}
